package tests;

import es.upm.gib.mappingAPI2.DatabaseInfo;
import es.upm.gib.mappingAPI2.FormatEncoder;
import es.upm.gib.mappingAPI2.MappingApi2;
import es.upm.gib.mappingAPI2.MappingMetadata;
import es.upm.gib.owlbasicmodel2.OWLBasicModel2;
import org.jdom2.JDOMException;

import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Ana Escrich
 * Date: 11/05/12
 * Time: 16:48
 * To change this template use File | Settings | File Templates.
 */
public class Test {
    public static void main(String args[]) throws Exception, ParseException {
        FormatEncoder d = new FormatEncoder();
        d.readFromString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<mapping>\n" +
                "  <metadata>\n" +
                "    <mapping_name>clin1</mapping_name>\n" +
                "    <description>clinical-db.owl</description>\n" +
                "    <data_base_info>\n" +
                "      <db_url>clinical-db.owl</db_url>\n" +
                "    </data_base_info>\n" +
                "    <authors>\n" +
                "      <author>d34e744d-fe90-4f53-8b77-28fd2662f2ee</author>\n" +
                "    </authors>\n" +
                "    <creation_date>Fri Mar 15 13:06:20 2013</creation_date>\n" +
                "    <last_modified_by>d34e744d-fe90-4f53-8b77-28fd2662f2ee</last_modified_by>\n" +
                "    <last_modification_date>Tue Mar 05 10:35:37 2013</last_modification_date>\n" +
                "    <custom_data>\n" +
                "      <row>\n" +
                "        <index>Last Entry</index>\n" +
                "        <value>-1</value>\n" +
                "      </row>\n" +
                "    </custom_data>\n" +
                "  </metadata>\n" +
                "</mapping>");
        PruebaXML();
        //MappingApi2 mappingApi2Prueba = new MappingApi2();
        FormatEncoder formatEncoder = new FormatEncoder();
        MappingApi2 mappingApi2Prueba = formatEncoder.readFromString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<mapping>\n" +
                "<metadata>\n" +
                "<mapping_name>sdfsd</mapping_name>\n" +
                "<description>sdfs</description>\n" +
                "<data_base_info>\n" +
                "<db_url>clinical-db.owl</db_url>\n" +
                "</data_base_info>\n" +
                "<authors>\n" +
                "<author>fff</author>\n" +
                "</authors>\n" +
                "<creation_date>Wed Nov 21 16:18:20 2012</creation_date>\n" +
                "<last_modified_by>fff</last_modified_by>\n" +
                "<last_modification_date>Wed Nov 21 16:18:20 2012</last_modification_date>\n" +
                "</metadata>\n" +
                "</mapping>\n" +
                "");

        String path = "C:\\Users\\Ana Escrich\\Dropbox\\cosas Ana\\curro\\clinical-db.owl";
        int i = 1;
        OWLBasicModel2 OwlModel = OWLBasicModel2.parseFile(path);

        String physicalView = "[[[1,1,[[2,\"http://www.ont-annotator-example-clinicalDB.owl#undergoes\"],[3,\"http://www.ont-annotator-example-clinicalDB.owl#undergoes\"]],\"http://www.ont-annotator-example-clinicalDB.owl#Patient\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasAge\",\"http://www.w3.org/2001/XMLSchema#int\"],[\"http://www.ont-annotator-example-clinicalDB.owl#hasGender\",\"http://www.w3.org/2001/XMLSchema#string\"],[\"http://www.ont-annotator-example-clinicalDB.owl#hasName\",\"http://www.w3.org/2001/XMLSchema#string\"]]],[2,1,[],\"http://www.ont-annotator-example-clinicalDB.owl#ClinicalTreatment\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\",\"http://www.w3.org/2001/XMLSchema#date\"]]],[3,1,[[4,\"http://www.ont-annotator-example-clinicalDB.owl#reveals\"]],\"http://www.ont-annotator-example-clinicalDB.owl#MedicalTest\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\",\"http://www.w3.org/2001/XMLSchema#date\"]]],[4,3,[],\"http://www.ont-annotator-example-clinicalDB.owl#HealthStatus\",[]]]]";
        String conceptualView = "[[[1,1,[[2,\"http://www.ont-annotator-example-clinicalDB.owl#treats\"]],\"http://www.ont-annotator-example-clinicalDB.owl#Clinician\",[]],[2,1,[[3,\"http://www.ont-annotator-example-clinicalDB.owl#undergoes\"]],\"http://www.ont-annotator-example-clinicalDB.owl#Patient\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasAge\",\"http://www.w3.org/2001/XMLSchema#int\"]]],[3,2,[],\"http://www.ont-annotator-example-clinicalDB.owl#Treatment\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\",\"http://www.w3.org/2001/XMLSchema#date\"]]]]]";
        physicalView = "[[[1,1,[[2,\"http://www.ont-annotator-example-clinicalDB.owl#undergoes\"],[3,\"http://www.ont-annotator-example-clinicalDB.owl#undergoes\"]],\"http://www.ont-annotator-example-clinicalDB.owl#Patient\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasAge\",\"http://www.w3.org/2001/XMLSchema#int\",1],[\"http://www.ont-annotator-example-clinicalDB.owl#hasGender\",\"http://www.w3.org/2001/XMLSchema#string\",0],[\"http://www.ont-annotator-example-clinicalDB.owl#hasName\",\"http://www.w3.org/2001/XMLSchema#string\",1]],1],[2,1,[],\"http://www.ont-annotator-example-clinicalDB.owl#ClinicalTreatment\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\",\"http://www.w3.org/2001/XMLSchema#date\",1]],0],[3,1,[[4,\"http://www.ont-annotator-example-clinicalDB.owl#reveals\"]],\"http://www.ont-annotator-example-clinicalDB.owl#MedicalTest\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\",\"http://www.w3.org/2001/XMLSchema#date\",1]],1],[4,3,[],\"http://www.ont-annotator-example-clinicalDB.owl#HealthStatus\",[],0]]]";
        conceptualView = "[[[1,1,[[2,\"http://www.ont-annotator-example-clinicalDB.owl#treats\"]],\"http://www.ont-annotator-example-clinicalDB.owl#Clinician\",[],0],[2,1,[[3,\"http://www.ont-annotator-example-clinicalDB.owl#undergoes\"]],\"http://www.ont-annotator-example-clinicalDB.owl#Patient\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasAge\",\"http://www.w3.org/2001/XMLSchema#int\",1]],1],[3,2,[],\"http://www.ont-annotator-example-clinicalDB.owl#Treatment\",[[\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\",\"http://www.w3.org/2001/XMLSchema#date\",1]],0]]]";
        String mapping = "[[C,[1,\"http://www.ont-annotator-example-clinicalDB.owl#Patient\"],[2,\"http://www.ont-annotator-example-clinicalDB.owl#Patient\"]],[C,[3,\"http://www.ont-annotator-example-clinicalDB.owl#MedicalTest\"],[3,\"http://www.ont-annotator-example-clinicalDB.owl#Treatment\"]],[A,[1,\"http://www.ont-annotator-example-clinicalDB.owl#hasAge\"],[2,\"http://www.ont-annotator-example-clinicalDB.owl#hasAge\"]],[A,[3,\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\"],[3,\"http://www.ont-annotator-example-clinicalDB.owl#hasDate\"]]]";
        //Mapping map = new Mapping();
        //map.createMapping("ejemploMap1", "example of a mapping", "", "Ana Escrich");
        //map.createPaths(physicalView, mapping, conceptualView);

        //MappingApi2 mappingApi2 = map.getMappingApi2();
        MappingMetadata meta = new MappingMetadata("ejemplo1");
        meta.setMappingName("ejemploMap1");
        //meta.setDescription("example of a mapping");
        DatabaseInfo databaseInfo = new DatabaseInfo();
        databaseInfo.setDbName("clinical-db.owl");
        databaseInfo.setDbDescription("clinical database");
        databaseInfo.setDbUrl("http://achucarro.dia.fi.upm.es:8080/onts/clinical-db.owl");
        databaseInfo.setDbId("id1001");
        databaseInfo.setDbUsr("Ana");
        databaseInfo.setDbPsw("Escrich");
        meta.setDatabaseInfo(databaseInfo);
        //List<String> authors = new ArrayList<String>();
        /*authors.add("Ana Escrich");
        authors.add("Alberto Anguita");*/
        //meta.setAuthors(authors);
        Date date = new Date();
        meta.setCreationDate(date);
        meta.setLastModifiedBy("Ana Escrich");
        meta.setLastModificationDate(date);
        Map<String, String> abbreviationList = new HashMap<String, String>();
        abbreviationList.put("rdf", "http:balabla");
        abbreviationList.put("owl", "http:achublabla");
        meta.setAbbreviationList(abbreviationList);
       /* mappingApi2.setMetadata(meta);
        map.createEntry("Primera entry", "Ana", physicalView, mapping, conceptualView, -1);
        map.createEntry("Primera entry", "Alberto", physicalView, mapping, conceptualView, 0);
        
        File file = new File("J:\\p-medicine\\testJdom\\salidaAna2.xml");
        FormatEncoder f = new FormatEncoder(mappingApi2, file);*/
        FormatEncoder fe = new FormatEncoder();
        //f.submitXML();
        MappingApi2 mapFinal =fe.readFromXML("J:\\p-medicine\\testJdom\\salidaAna2.xml");

        //encoder.init();
        System.out.println("FIN");
    }

    public static void PruebaXML() throws IOException, JDOMException, ParseException {
        String path = "J:\\p-medicine\\tests\\mapping.xml";
        MappingApi2 mappingApi2 = new MappingApi2();
        FormatEncoder f = new FormatEncoder();
        mappingApi2 = f.readFromXML(path);
        mappingApi2.getEntries();
    }

}
